
clear
cd "YOUR FOLDER STRUCTURE"


****Second Vote - Parallel trends, Pre-Treatment
** National elections
*Treatment <=1km
clear
use "Data_NationalElection.dta", clear


gen time=.
replace time=0 if year==2013
replace time=1 if year==2017

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=1

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"

reg Share_Green time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_Gruene_did1
outreg2 using "TableA11_PanelA.xls", replace stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_Linke_did1
outreg2 using "TableA11_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_SPD_did1
outreg2 using "TableA11_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_coalition_did1
outreg2 using "TableA11_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Coalition) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_AfD_did1
outreg2 using "TableA11_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(AfD) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_CDU_did1
outreg2 using "TableA11_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_FDP_did1
outreg2 using "TableA11_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_opposition_did1
outreg2 using "TableA11_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_Wahlb_did1
outreg2 using "TableA11_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)



*Treatment <=3km
use "Data_NationalElection.dta", clear

gen time=.
replace time=0 if year==2013
replace time=1 if year==2017

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=3

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"


reg Share_Green time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_Gruene_did3
outreg2 using "TableA11_PanelB.xls", replace stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_Linke_did3
outreg2 using "TableA11_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_SPD_did3
outreg2 using "TableA11_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_coalition_did3
outreg2 using "TableA11_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Coalition) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_AfD_did3
outreg2 using "TableA11_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(AfD) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_CDU_did3
outreg2 using "TableA11_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_FDP_did3
outreg2 using "TableA11_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_opposition_did3
outreg2 using "TableA11_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_Wahlb_did3
outreg2 using "TableA11_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)




*Treatment <=5km
use "Data_NationalElection.dta", clear

gen time=.
replace time=0 if year==2013
replace time=1 if year==2017

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=5

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"

reg Share_Green time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_Gruene_did5
outreg2 using "TableA11_PanelC.xls", replace stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_Linke_did5
outreg2 using "TableA11_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_SPD_did5
outreg2 using "TableA11_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_coalition_did5
outreg2 using "TableA11_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Coalition) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_AfD_did5
outreg2 using "TableA11_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(AfD) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_CDU_did5
outreg2 using "TableA11_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_FDP_did5
outreg2 using "TableA11_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_opposition_did5
outreg2 using "TableA11_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_Wahlb_did5
outreg2 using "TableA11_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)



*Treatment <=10 km
use "Data_NationalElection.dta", clear

gen time=.
replace time=0 if year==2013
replace time=1 if year==2017

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=10

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"


reg Share_Green time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_Gruene_did10
outreg2 using "TableA11_PanelD.xls", replace stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_Linke_did10
outreg2 using "TableA11_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_SPD_did10
outreg2 using "TableA11_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_coalition_did10
outreg2 using "TableA11_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Coalition) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_AfD_did10
outreg2 using "TableA11_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(AfD) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_CDU_did10
outreg2 using "TableA11_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_FDP_did10
outreg2 using "TableA11_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_opposition_did10
outreg2 using "TableA11_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2021, vce(robust)
estimates store NE_2017_Wahlb_did10
outreg2 using "TableA11_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)



 

**State elections
use "Data_StateElection.dta", clear


gen time=.
replace time=0 if year==2014
replace time=1 if year==2019

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=1

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"

reg Share_Green time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_Gruene_did1
outreg2 using "TableA12_PanelA.xls", replace stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_Linke_did1
outreg2 using "TableA12_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_SPD_did1
outreg2 using "TableA12_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_coalition_did1
outreg2 using "TableA12_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(coalition) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_AfD_did1
outreg2 using "TableA12_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(AfD) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_CDU_did1
outreg2 using "TableA12_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_FDP_did1
outreg2 using "TableA12_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_opposition_did1
outreg2 using "TableA12_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_Wahlb_did1
outreg2 using "TableA12_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)



*Treatment <=3km
use "Data_StateElection.dta", clear

gen time=.
replace time=0 if year==2014
replace time=1 if year==2019

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=3

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"


reg Share_Green time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_Gruene_did3
outreg2 using "TableA12_PanelB.xls", replace stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_Linke_did3
outreg2 using "TableA12_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_SPD_did3
outreg2 using "TableA12_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_coalition_did3
outreg2 using "TableA12_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(coalition) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_AfD_did3
outreg2 using "TableA12_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(AfD) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_CDU_did3
outreg2 using "TableA12_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_FDP_did3
outreg2 using "TableA12_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_opposition_did3
outreg2 using "TableA12_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_Wahlb_did3
outreg2 using "TableA12_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)




*Treatment <=5km
use "Data_StateElection.dta", clear

gen time=.
replace time=0 if year==2014
replace time=1 if year==2019

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=5

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"

reg Share_Green time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_Gruene_did5
outreg2 using "TableA12_PanelC.xls", replace stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_Linke_did5
outreg2 using "TableA12_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_SPD_did5
outreg2 using "TableA12_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_coalition_did5
outreg2 using "TableA12_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(coalition) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_AfD_did5
outreg2 using "TableA12_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(AfD) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_CDU_did5
outreg2 using "TableA12_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_FDP_did5
outreg2 using "TableA12_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_opposition_did5
outreg2 using "TableA12_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_Wahlb_did5
outreg2 using "TableA12_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)



*Treatment <=10 km
use "Data_StateElection.dta", clear

gen time=.
replace time=0 if year==2014
replace time=1 if year==2019

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=10

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"


reg Share_Green time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_Gruene_did10
outreg2 using "TableA12_PanelD.xls", replace stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_Linke_did10
outreg2 using "TableA12_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_SPD_did10
outreg2 using "TableA12_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_coalition_did10
outreg2 using "TableA12_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(coalition) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_AfD_did10
outreg2 using "TableA12_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(AfD) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_CDU_did10
outreg2 using "TableA12_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_FDP_did10
outreg2 using "TableA12_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_opposition_did10
outreg2 using "TableA12_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2024, vce(robust)
estimates store SE_2019_Wahlb_did10
outreg2 using "TableA12_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)





*Regional Elections

use "Data_RegionalElection.dta", clear


gen time=.
replace time=0 if year==2014
replace time=1 if year==2019

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=1

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"

reg Share_Green time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Gruene_did1
outreg2 using "TableA13_PanelA.xls", replace stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Linke_did1
outreg2 using "TableA13_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_SPD_did1
outreg2 using "TableA13_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_coalition_did1
outreg2 using "TableA13_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Coalition) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_FarRight time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_FarRight_did1
outreg2 using "TableA13_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(FarRight) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_CDU_did1
outreg2 using "TableA13_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_FDP_did1
outreg2 using "TableA13_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition1 time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Opposition1_did1
outreg2 using "TableA13_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Opposition1) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Wahlb_did1
outreg2 using "TableA13_PanelA.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)



*Treatment <=3km
use "Data_RegionalElection.dta", clear

gen time=.
replace time=0 if year==2014
replace time=1 if year==2019

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=3

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"


reg Share_Green time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Gruene_did3
outreg2 using "TableA13_PanelB.xls", replace stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Linke_did3
outreg2 using "TableA13_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_SPD_did3
outreg2 using "TableA13_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_coalition_did3
outreg2 using "TableA13_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Coalition) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_FarRight time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_FarRight_did3
outreg2 using "TableA13_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(FarRight) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_CDU_did3
outreg2 using "TableA13_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_FDP_did3
outreg2 using "TableA13_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition1 time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Opposition1_did3
outreg2 using "TableA13_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Opposition1) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Wahlb_did3
outreg2 using "TableA13_PanelB.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)




*Treatment <=5km
use "Data_RegionalElection.dta", clear

gen time=.
replace time=0 if year==2014
replace time=1 if year==2019

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=5

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"

reg Share_Green time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Gruene_did5
outreg2 using "TableA13_PanelC.xls", replace stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Linke_did5
outreg2 using "TableA13_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_SPD_did5
outreg2 using "TableA13_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_coalition_did5
outreg2 using "TableA13_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Coalition) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_FarRight time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_FarRight_did5
outreg2 using "TableA13_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(FarRight) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_CDU_did5
outreg2 using "TableA13_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_FDP_did5
outreg2 using "TableA13_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition1 time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Opposition1_did5
outreg2 using "TableA13_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Opposition1) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Wahlb_did5
outreg2 using "TableA13_PanelC.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)



*Treatment <=10 km
use "Data_RegionalElection.dta", clear

gen time=.
replace time=0 if year==2014
replace time=1 if year==2019

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=10

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"


reg Share_Green time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Gruene_did10
outreg2 using "TableA13_PanelD.xls", replace stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Linke_did10
outreg2 using "TableA13_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_SPD_did10
outreg2 using "TableA13_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_coalition_did10
outreg2 using "TableA13_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Coalition) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_FarRight time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_FarRight_did10
outreg2 using "TableA13_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(FarRight) keep(did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_CDU_did10
outreg2 using "TableA13_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_FDP_did10
outreg2 using "TableA13_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition1 time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Opposition1_did10
outreg2 using "TableA13_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Opposition1) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2024, vce(robust)
estimates store RE_2019_Wahlb_did10
outreg2 using "TableA13_PanelD.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 keep(did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)



 
coefplot ///
(NE_2017_Gruene_did1, mcolor(green) ciopts(color(green)recast(rcap))) (NE_2017_Linke_did1, mcolor(purple) ciopts(color(purple)recast(rcap))) (NE_2017_SPD_did1, mcolor(red)ciopts(color(red)recast(rcap))) (NE_2017_coalition_did1, msymbol(D) mcolor(emerald) ciopts(color(emerald)recast(rcap))) (NE_2017_AfD_did1, mcolor(blue) ciopts(color(blue)recast(rcap)))  (NE_2017_CDU_did1, mcolor(black) ciopts(color(black)recast(rcap))) (NE_2017_FDP_did1, mcolor(yellow) ciopts(color(yellow)recast(rcap))) (NE_2017_opposition_did1, msymbol(S) mcolor(navy) ciopts(color(navy)recast(rcap))) (NE_2017_Wahlb_did1, msymbol(T) mcolor(brown) ciopts(color(brown)recast(rcap))), bylabel(National Election) || ///
SE_2019_Gruene_did1 SE_2019_Linke_did1 SE_2019_SPD_did1 SE_2019_coalition_did1 SE_2019_AfD_did1 SE_2019_CDU_did1 SE_2019_FDP_did1 SE_2019_opposition_did1 SE_2019_Wahlb_did1, bylabel(State election) || ///
RE_2019_Gruene_did1 RE_2019_Linke_did1 RE_2019_SPD_did1 RE_2019_coalition_did1 RE_2019_FarRight_did1 RE_2019_CDU_did1 RE_2019_FDP_did1 RE_2019_Opposition1_did1 RE_2019_Wahlb_did1, bylabel(Regional election) || ///
NE_2017_Gruene_did3 NE_2017_Linke_did3 NE_2017_SPD_did3 NE_2017_coalition_did3 NE_2017_AfD_did3 NE_2017_CDU_did3 NE_2017_FDP_did3 NE_2017_opposition_did3 NE_2017_Wahlb_did3, bylabel("") ||  ///
SE_2019_Gruene_did3 SE_2019_Linke_did3 SE_2019_SPD_did3 SE_2019_coalition_did3 SE_2019_AfD_did3 SE_2019_CDU_did3 SE_2019_FDP_did3 SE_2019_opposition_did3 SE_2019_Wahlb_did3, bylabel("") ||  ///
RE_2019_Gruene_did3 RE_2019_Linke_did3 RE_2019_SPD_did3 RE_2019_coalition_did3 RE_2019_FarRight_did3 RE_2019_CDU_did3 RE_2019_FDP_did3 RE_2019_Opposition1_did3 RE_2019_Wahlb_did3, bylabel("") ||  ///
NE_2017_Gruene_did5 NE_2017_Linke_did5 NE_2017_SPD_did5 NE_2017_coalition_did5 NE_2017_AfD_did5 NE_2017_CDU_did5 NE_2017_FDP_did5 NE_2017_opposition_did5 NE_2017_Wahlb_did5, bylabel("") ||  ///
SE_2019_Gruene_did5 SE_2019_Linke_did5 SE_2019_SPD_did5 SE_2019_coalition_did5 SE_2019_AfD_did5 SE_2019_CDU_did5 SE_2019_FDP_did5 SE_2019_opposition_did5 SE_2019_Wahlb_did5, bylabel("") ||  ///
RE_2019_Gruene_did5 RE_2019_Linke_did5 RE_2019_SPD_did5 RE_2019_coalition_did5 RE_2019_FarRight_did5 RE_2019_CDU_did5 RE_2019_FDP_did5 RE_2019_Opposition1_did5 RE_2019_Wahlb_did5, bylabel("") ||  ///
NE_2017_Gruene_did10 NE_2017_Linke_did10 NE_2017_SPD_did10 NE_2017_coalition_did10 NE_2017_AfD_did10 NE_2017_CDU_did10 NE_2017_FDP_did10 NE_2017_opposition_did10 NE_2017_Wahlb_did10, bylabel("") || ///
SE_2019_Gruene_did10 SE_2019_Linke_did10 SE_2019_SPD_did10 SE_2019_coalition_did10 SE_2019_AfD_did10 SE_2019_CDU_did10 SE_2019_FDP_did10 SE_2019_opposition_did10 SE_2019_Wahlb_did10, bylabel("") || ///
RE_2019_Gruene_did10 RE_2019_Linke_did10 RE_2019_SPD_did10 RE_2019_coalition_did10 RE_2019_FarRight_did10 RE_2019_CDU_did10 RE_2019_FDP_did10 RE_2019_Opposition1_did10 RE_2019_Wahlb_did10, bylabel("") ///
drop(_cons) xline(0) ciopts(recast(rcap)) keep(did) levels(95) ///
 legend(size(*0.75)cols(4)label(2 "Green")label(4 "Left")label(6 "SPD")label(8 "Coalition")label(10 "AfD/FarRight")label(12 "CDU")label(14 "FDP")label(16 "Opposition")label(18 "Voter turnout")) ///
 byopts(cols(3))
graph play "Figure3_Results_PreTreatment.grec"
graph save Graph "Figure3_Results_PreTreatment.gph", replace
graph export "Figure3_Results_Pretreatment.png", as(png) replace
 


 


*Test of Orthogonality (Beaman et al. 2023, Econometrica)
use "Data_NationalElection.dta", clear

keep if year==2017
gen treated=0
replace treated=1 if Distance_Apfelstaedt<=1

regress treated Distance_windturbines Distance_cities Distance_highways Distance_railways Elevation Female_share Kids_0_17_share Retired_share Share_foreigners Pop_size Pop_growth Income_per_capita Unemployment_rate, vce(robust)
local fmodel = Ftail(`e(df_m)',`e(df_r)',`e(F)')
outreg2 using "Table2.xls", replace stat(coef se) dec(2) label adjr2 addstat("F test model", e(F),"P-value of F model", `fmodel') alpha(0.001, 0.01, 0.05)




****Main Analysis, Second Vote - Post-treatment
** National elections
*Treatment <=1km
clear
use "Data_NationalElection.dta", clear

gen time=.
replace time=0 if year==2017
replace time=1 if year==2021

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=1

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"

reg Share_Green time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_Gruene_did1
outreg2 using "TableA2_PanelA.xls", replace stat(coef se) dec(2) nocons label adjr2 ctitle(Green) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_Linke_did1
outreg2 using "TableA2_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_SPD_did1
outreg2 using "TableA2_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_coalition_did1
outreg2 using "TableA2_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(Coalition) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_AfD_did1
outreg2 using "TableA2_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(AfD) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_CDU_did1
outreg2 using "TableA2_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_FDP_did1
outreg2 using "TableA2_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_opposition_did1
outreg2 using "TableA2_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_Wahlb_did1
outreg2 using "TableA2_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)



   

collapseJ (mean) Share_Green Share_Left Share_SPD Share_coalition Share_AfD Share_CDU Share_FDP Share_opposition Voter_turnout, by(year treated)
lab var year "Year"

twoway ///
  line Share_Green year if treated==0, lp(dash) xlabel(2013 2017 2021) ytitle("Share in %" " ") subtitle("Green") || /// Linie für treated==0
  line Share_Green year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 3 2017 4.5 2017, recast(line) lp(dot) lcolor(black) lwidth(thick) /// /// Vertikale Linie
  legend(rows(1) order(2 1 3) label(1 "Not treated") label(2 "Treated<=1 km") label(3 "Last election before treatment")) /// 
  name(panel_11, replace)
	graph save panel_11 "Figure5_National_Election_Green.gph", replace

twoway ///
  line Share_Left year if treated==0, lp(dash) xlabel(2013 2017 2021) ytitle("Share in %" " ") subtitle("Left") || /// Linie für treated==0
  line Share_Left year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 10 2017 25 2017, recast(line) lp(dot) lcolor(black) lwidth(thick) /// /// Vertikale Linie
  legend(rows(1) order(2 1 3) label(1 "Not treated") label(2 "Treated<=1 km") label(3 "Last election before treatment")) /// 
  name(panel_12, replace)
	graph save panel_12 "Figure5_National_Election_Left.gph", replace

twoway ///
  line Share_SPD year if treated==0, lp(dash) xlabel(2013 2017 2021) ytitle("Share in %" " ") subtitle("SPD") || /// Linie für treated==0
  line Share_SPD year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 10 2017 25 2017, recast(line) lp(dot) lcolor(black) lwidth(thick) /// /// Vertikale Linie
  legend(rows(1) order(2 1 3) label(1 "Not treated") label(2 "Treated<=1 km") label(3 "Last election before treatment")) /// 
  name(panel_13, replace)
	graph save panel_13 "Figure5_National_Election_SPD.gph", replace
	
twoway ///
  line Share_coalition year if treated==0, lp(dash) xlabel(2013 2017 2021) ytitle("Share in %" " ") subtitle("Coalition") || /// Linie für treated==0
  line Share_coalition year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 30 2017 45 2017, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_14, replace)
	graph save panel_14 "Figure5_National_Election_Coalition.gph", replace
	
twoway ///
  line Share_AfD year if treated==0, lp(dash) xlabel(2013 2017 2021) ytitle("Share in %" " ") subtitle("AfD") || /// Linie für treated==0
  line Share_AfD year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 5 2017 27 2017, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_15, replace)
	graph save panel_15 "Figure5_National_Election_AfD.gph", replace

twoway ///
  line Share_CDU year if treated==0, lp(dash) xlabel(2013 2017 2021) ytitle("Share in %" " ") subtitle("CDU") || /// Linie für treated==0
  line Share_CDU year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 10 2017 50 2017, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_16, replace)
	graph save panel_16 "Figure5_National_Election_CDU.gph", replace

twoway ///
  line Share_FDP year if treated==0, lp(dash) xlabel(2013 2017 2021) ytitle("Share in %" " ") subtitle("FDP") || /// Linie für treated==0
  line Share_FDP year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 2 2017 10 2017, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_17, replace)
	graph save panel_17 "Figure5_National_Election_FDP.gph", replace

twoway ///
  line Share_opposition year if treated==0, lp(dash) xlabel(2013 2017 2021) ytitle("Share in %" " ") subtitle("Opposition") || /// Linie für treated==0
  line Share_opposition year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 50 2017 65 2017, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_18, replace)
	graph save panel_18 "Figure5_National_Election_Opposition.gph", replace

twoway ///
  line Voter_turnout year if treated==0, lp(dash) xlabel(2013 2017 2021) ytitle("Share in %" " ") subtitle("Voter Turnout") || /// Linie für treated==0
  line Voter_turnout year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 70 2017 85 2017, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_19, replace)
	graph save panel_19 "Figure5_National_Election_VoterTurnout.gph", replace




*Treatment <=3km
use "Data_NationalElection.dta", clear

gen time=.
replace time=0 if year==2017
replace time=1 if year==2021

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=3

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"


reg Share_Green time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_Gruene_did3
outreg2 using "TableA2_PanelB.xls", replace stat(coef se) dec(2) nocons label adjr2 ctitle(Green) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_Linke_did3
outreg2 using "TableA2_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_SPD_did3
outreg2 using "TableA2_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_coalition_did3
outreg2 using "TableA2_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(Coalition) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_AfD_did3
outreg2 using "TableA2_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(AfD) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_CDU_did3
outreg2 using "TableA2_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_FDP_did3
outreg2 using "TableA2_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_opposition_did3
outreg2 using "TableA2_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_Wahlb_did3
outreg2 using "TableA2_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)



*Treatment <=5km
use "Data_NationalElection.dta", clear

gen time=.
replace time=0 if year==2017
replace time=1 if year==2021

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=5

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"

reg Share_Green time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_Gruene_did5
outreg2 using "TableA2_PanelC.xls", replace stat(coef se) dec(2) nocons label adjr2 ctitle(Green) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_Linke_did5
outreg2 using "TableA2_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_SPD_did5
outreg2 using "TableA2_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_coalition_did5
outreg2 using "TableA2_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(Coalition) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_AfD_did5
outreg2 using "TableA2_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(AfD) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_CDU_did5
outreg2 using "TableA2_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_FDP_did5
outreg2 using "TableA2_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_opposition_did5
outreg2 using "TableA2_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_Wahlb_did5
outreg2 using "TableA2_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)




*Treatment <=10 km
use "Data_NationalElection.dta", clear

gen time=.
replace time=0 if year==2017
replace time=1 if year==2021

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=10

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"



reg Share_Green time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_Gruene_did10
outreg2 using "TableA2_PanelD.xls", replace stat(coef se) dec(2) nocons label adjr2 ctitle(Green) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_Linke_did10
outreg2 using "TableA2_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_SPD_did10
outreg2 using "TableA2_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_coalition_did10
outreg2 using "TableA2_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(Coalition) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_AfD_did10
outreg2 using "TableA2_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(AfD) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_CDU_did10
outreg2 using "TableA2_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_FDP_did10
outreg2 using "TableA2_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_opposition_did10
outreg2 using "TableA2_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2013, vce(robust)
estimates store NE_2021_Wahlb_did10
outreg2 using "TableA2_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)





** State elections
*Treatment <=1km
clear
use "Data_StateElection.dta", clear


gen time=.
replace time=0 if year==2019
replace time=1 if year==2024

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=1

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"


reg Share_Green time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_Gruene_did1
outreg2 using "TableA3_PanelA.xls", replace stat(coef se) dec(2) nocons label adjr2 ctitle(Green) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_Linke_did1
outreg2 using "TableA3_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_SPD_did1
outreg2 using "TableA3_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_coalition_did1
outreg2 using "TableA3_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(Coalition) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_AfD_did1
outreg2 using "TableA3_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(AfD) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_CDU_did1
outreg2 using "TableA3_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_FDP_did1
outreg2 using "TableA3_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_opposition_did1
outreg2 using "TableA3_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_Wahlb_did1
outreg2 using "TableA3_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)




collapseJ (mean) Share_Green Share_Left Share_SPD Share_coalition Share_AfD Share_CDU Share_FDP Share_opposition Voter_turnout, by(year treated)
lab var year "Year"


twoway ///
  line Share_Green year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("Green") || /// Linie für treated==0
  line Share_Green year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 1 2019 5 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) /// /// Vertikale Linie
  legend(rows(1) order(2 1 3) label(1 "Not treated") label(2 "Treated<=1 km") label(3 "Last election before treatment")) /// 
  name(panel_21, replace)
	graph save panel_21 "Figure6_State_Election_Green.gph", replace

twoway ///
  line Share_Left year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("Left") || /// Linie für treated==0
  line Share_Left year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 10 2019 31 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) /// /// Vertikale Linie
  legend(rows(1) order(2 1 3) label(1 "Not treated") label(2 "Treated<=1 km") label(3 "Last election before treatment")) /// 
  name(panel_22, replace)
	graph save panel_22 "Figure6_State_Election_Left.gph", replace

twoway ///
  line Share_SPD year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("SPD") || /// Linie für treated==0
  line Share_SPD year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 6 2019 14 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) /// /// Vertikale Linie
  legend(rows(1) order(2 1 3) label(1 "Not treated") label(2 "Treated<=1 km") label(3 "Last election before treatment")) /// 
  name(panel_23, replace)
	graph save panel_23 "Figure6_State_Election_SPD.gph", replace
	
twoway ///
  line Share_coalition year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("Coalition") || /// Linie für treated==0
  line Share_coalition year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 20 2019 50 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_24, replace)
	graph save panel_24 "Figure6_State_Election_Coalition.gph", replace
	
twoway ///
  line Share_AfD year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("AfD") || /// Linie für treated==0
  line Share_AfD year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 10 2019 35 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_25, replace)
	graph save panel_25 "Figure6_State_Election_AfD.gph", replace

twoway ///
  line Share_CDU year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("CDU") || /// Linie für treated==0
  line Share_CDU year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 20 2019 36 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_26, replace)
	graph save panel_26 "Figure6_State_Election_CDU.gph", replace

twoway ///
  line Share_FDP year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("FDP") || /// Linie für treated==0
  line Share_FDP year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 1 2019 5.1 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_27, replace)
	graph save panel_27 "Figure6_State_Election_FDP.gph", replace

twoway ///
  line Share_opposition year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("Opposition") || /// Linie für treated==0
  line Share_opposition year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 49 2019 60 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_28, replace)
	graph save panel_28 "Figure6_State_Election_Opposition.gph", replace

twoway ///
  line Voter_turnout year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("Voter Turnout") || /// Linie für treated==0
  line Voter_turnout year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 55 2019 80 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_29, replace)
	graph save panel_29 "Figure6_State_Election_VoterTurnout.gph", replace

	
	
	
*Treatment <=3km
use "Data_StateElection.dta", clear

gen time=.
replace time=0 if year==2019
replace time=1 if year==2024

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=3

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"


reg Share_Green time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_Gruene_did3
outreg2 using "TableA3_PanelB.xls", replace stat(coef se) dec(2) nocons label adjr2 ctitle(Green) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_Linke_did3
outreg2 using "TableA3_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_SPD_did3
outreg2 using "TableA3_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_coalition_did3
outreg2 using "TableA3_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(Coalition) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_AfD_did3
outreg2 using "TableA3_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(AfD) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_CDU_did3
outreg2 using "TableA3_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_FDP_did3
outreg2 using "TableA3_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_opposition_did3
outreg2 using "TableA3_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_Wahlb_did3
outreg2 using "TableA3_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)




*Treatment <=5km
use "Data_StateElection.dta", clear

gen time=.
replace time=0 if year==2019
replace time=1 if year==2024

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=5

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"

reg Share_Green time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_Gruene_did5
outreg2 using "TableA3_PanelC.xls", replace stat(coef se) dec(2) nocons label adjr2 ctitle(Green) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_Linke_did5
outreg2 using "TableA3_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_SPD_did5
outreg2 using "TableA3_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_coalition_did5
outreg2 using "TableA3_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(Coalition) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_AfD_did5
outreg2 using "TableA3_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(AfD) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_CDU_did5
outreg2 using "TableA3_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_FDP_did5
outreg2 using "TableA3_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_opposition_did5
outreg2 using "TableA3_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_Wahlb_did5
outreg2 using "TableA3_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)



*Treatment <=10 km
use "Data_StateElection.dta", clear

gen time=.
replace time=0 if year==2019
replace time=1 if year==2024

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=10

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"


reg Share_Green time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_Gruene_did10
outreg2 using "TableA3_PanelD.xls", replace stat(coef se) dec(2) nocons label adjr2 ctitle(Green) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_Linke_did10
outreg2 using "TableA3_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_SPD_did10
outreg2 using "TableA3_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_coalition_did10
outreg2 using "TableA3_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(Coalition) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_AfD_did10
outreg2 using "TableA3_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(AfD) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_CDU_did10
outreg2 using "TableA3_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_FDP_did10
outreg2 using "TableA3_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_opposition_did10
outreg2 using "TableA3_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2014, vce(robust)
estimates store SE_2024_Wahlb_did10
outreg2 using "TableA3_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)


 
 
** Regional elections
*Treatment <=1km
clear
use "Data_RegionalElection.dta", clear

gen time=.
replace time=0 if year==2019
replace time=1 if year==2024

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=1

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"

reg Share_Green time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Gruene_did1
outreg2 using "TableA4_PanelA.xls", replace stat(coef se) dec(2) nocons label adjr2 ctitle(Green) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Linke_did1
outreg2 using "TableA4_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_SPD_did1
outreg2 using "TableA4_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_coalition_did1
outreg2 using "TableA4_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(Coalition) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_AfD_did1
outreg2 using "TableA4_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(AfD) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_CDU_did1
outreg2 using "TableA4_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_FDP_did1
outreg2 using "TableA4_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition2 time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_opposition_did1
outreg2 using "TableA4_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Wahlb_did1
outreg2 using "TableA4_PanelA.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)



collapseJ (mean) Share_Green Share_Left Share_SPD Share_coalition Share_AfD Share_FarRight Share_CDU Share_FDP Share_opposition2 Voter_turnout, by(year treated)
lab var year "Year"


twoway ///
  line Share_Green year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("Green") || /// Linie für treated==0
  line Share_Green year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 2 2019 6 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) /// /// Vertikale Linie
  legend(rows(1) order(2 1 3) label(1 "Not treated") label(2 "Treated<=1 km") label(3 "Last election before treatment")) /// 
  name(panel_31, replace)
	graph save panel_31 "Figure7_Regional_Election_Green.gph", replace

twoway ///
  line Share_Left year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("Left") || /// Linie für treated==0
  line Share_Left year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 4 2019 15 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) /// /// Vertikale Linie
  legend(rows(1) order(2 1 3) label(1 "Not treated") label(2 "Treated<=1 km") label(3 "Last election before treatment")) /// 
  name(panel_32, replace)
	graph save panel_32 "Figure7_Regional_Election_Left.gph", replace

twoway ///
  line Share_SPD year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("SPD") || /// Linie für treated==0
  line Share_SPD year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 18 2019 26 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) /// /// Vertikale Linie
  legend(rows(1) order(2 1 3) label(1 "Not treated") label(2 "Treated<=1 km") label(3 "Last election before treatment")) /// 
  name(panel_33, replace)
	graph save panel_33 "Figure7_Regional_Election_SPD.gph", replace
	
twoway ///
  line Share_coalition year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("Coalition") || /// Linie für treated==0
  line Share_coalition year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 25 2019 45 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_34, replace)
	graph save panel_34 "Figure7_Regional_Election_Coalition.gph", replace
	
twoway ///
  line Share_FarRight year if treated==0, lp(dash) xlabel(2014 2019 2024) subtitle("AfD/Far-right") || /// Linie für treated==0
  line Share_FarRight year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 4 2019 30 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_35, replace)
	graph save panel_35 "Figure7_Regional_Election_AfD.gph", replace


twoway ///
  line Share_CDU year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("CDU") || /// Linie für treated==0
  line Share_CDU year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 25 2019 45 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_36, replace)
	graph save panel_36 "Figure7_Regional_Election_CDU.gph", replace

twoway ///
  line Share_FDP year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("FDP") || /// Linie für treated==0
  line Share_FDP year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 1 2019 3.5 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_37, replace)
	graph save panel_37 "Figure7_Regional_Election_FDP.gph", replace

twoway ///
  line Share_opposition year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("Opposition") || /// Linie für treated==0
  line Share_opposition year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 44 2019 60 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_38, replace)
	graph save panel_38 "Figure7_Regional_Election_Opposition.gph", replace

twoway ///
  line Voter_turnout year if treated==0, lp(dash) xlabel(2014 2019 2024) ytitle("Share in %" " ") subtitle("Voter Turnout") || /// Linie für treated==0
  line Voter_turnout year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 55 2019 75 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) ///
	legend(off) ///
  name(panel_39, replace)
	graph save panel_39 "Figure7_Regional_Election_VoterTurnout.gph", replace

grc1leg2 ///
panel_11 panel_12 panel_13 panel_14 panel_15 panel_16 panel_17 panel_18 panel_19 ///
, col(3) ysize(7.000) title("Voting trends National Election", size(small))
graph save Graph "Figure5_Voting_Trends_Over_Time_NationalElection.gph", replace
graph export "Figure5_Voting_Trends_Over_Time_NationalElection.png", as(png) replace	

grc1leg2 ///
panel_21 panel_22 panel_23 panel_24 panel_25 panel_26 panel_27 panel_28 panel_29 ///
, col(3) ysize(7.000) title("Voting trends State Election", size(small))
graph save Graph "Figure6_Voting_Trends_Over_Time_StateElection.gph", replace
graph export "Figure6_Voting_Trends_Over_Time_StateElection.png", as(png) replace	

grc1leg2 ///
panel_31 panel_32 panel_33 panel_34 panel_35 panel_36 panel_37 panel_38 panel_39 ///
, col(3) ysize(7.000) title("Voting trends Regional Election", size(small))
graph save Graph "Figure7_Voting_Trends_Over_Time_RegionalElection.gph", replace
graph export "Figure7_Voting_Trends_Over_Time_RegionalElection.png", as(png) replace	



	 
*Treatment <=3km
use "Data_RegionalElection.dta", clear

gen time=.
replace time=0 if year==2019
replace time=1 if year==2024

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=3

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"


reg Share_Green time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Gruene_did3
outreg2 using "TableA4_PanelB.xls", replace stat(coef se) dec(2) nocons label adjr2 ctitle(Green) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Linke_did3
outreg2 using "TableA4_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_SPD_did3
outreg2 using "TableA4_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_coalition_did3
outreg2 using "TableA4_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(Coalition) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_AfD_did3
outreg2 using "TableA4_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(AfD) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_CDU_did3
outreg2 using "TableA4_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_FDP_did3
outreg2 using "TableA4_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition2 time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_opposition_did3
outreg2 using "TableA4_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Wahlb_did3
outreg2 using "TableA4_PanelB.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)




*Treatment <=5km
use "Data_RegionalElection.dta", clear

gen time=.
replace time=0 if year==2019
replace time=1 if year==2024

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=5

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"

reg Share_Green time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Gruene_did5
outreg2 using "TableA4_PanelC.xls", replace stat(coef se) dec(2) nocons label adjr2 ctitle(Green) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Linke_did5
outreg2 using "TableA4_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_SPD_did5
outreg2 using "TableA4_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_coalition_did5
outreg2 using "TableA4_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(Coalition) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_AfD_did5
outreg2 using "TableA4_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(AfD) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_CDU_did5
outreg2 using "TableA4_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_FDP_did5
outreg2 using "TableA4_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition2 time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_opposition_did5
outreg2 using "TableA4_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Wahlb_did5
outreg2 using "TableA4_PanelC.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)




*Treatment <=10 km
use "Data_RegionalElection.dta", clear

gen time=.
replace time=0 if year==2019
replace time=1 if year==2024

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=10

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"


reg Share_Green time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Gruene_did10
outreg2 using "TableA4_PanelD.xls", replace stat(coef se) dec(2) nocons label adjr2 ctitle(Green) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_Left time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Linke_did10
outreg2 using "TableA4_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Left) alpha(0.001, 0.01, 0.05)

reg Share_SPD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_SPD_did10
outreg2 using "TableA4_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(SPD) alpha(0.001, 0.01, 0.05)

reg Share_coalition time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_coalition_did10
outreg2 using "TableA4_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(Coalition) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_AfD time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_AfD_did10
outreg2 using "TableA4_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 ctitle(AfD) keep(time treated did) alpha(0.001, 0.01, 0.05)

reg Share_CDU time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_CDU_did10
outreg2 using "TableA4_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(CDU) alpha(0.001, 0.01, 0.05)

reg Share_FDP time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_FDP_did10
outreg2 using "TableA4_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(FDP) alpha(0.001, 0.01, 0.05)

reg Share_opposition2 time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_opposition_did10
outreg2 using "TableA4_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Opposition) alpha(0.001, 0.01, 0.05)

reg Voter_turnout time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Wahlb_did10
outreg2 using "TableA4_PanelD.xls", stat(coef se) dec(2) nocons label adjr2 keep(time treated did) ctitle(Voter turnout) alpha(0.001, 0.01, 0.05)



coefplot ///
(NE_2021_Gruene_did1, mcolor(green) ciopts(color(green)recast(rcap))) (NE_2021_Linke_did1, mcolor(purple) ciopts(color(purple)recast(rcap))) (NE_2021_SPD_did1, mcolor(red)ciopts(color(red)recast(rcap))) (NE_2021_coalition_did1, msymbol(D) mcolor(emerald) ciopts(color(emerald)recast(rcap))) (NE_2021_AfD_did1, mcolor(blue) ciopts(color(blue)recast(rcap)))  (NE_2021_CDU_did1, mcolor(black) ciopts(color(black)recast(rcap))) (NE_2021_FDP_did1, mcolor(yellow) ciopts(color(yellow)recast(rcap))) (NE_2021_opposition_did1, msymbol(S) mcolor(navy) ciopts(color(navy)recast(rcap))) (NE_2021_Wahlb_did1, msymbol(T) mcolor(brown) ciopts(color(brown)recast(rcap))), bylabel(National Election) || ///
SE_2024_Gruene_did1 SE_2024_Linke_did1 SE_2024_SPD_did1 SE_2024_coalition_did1 SE_2024_AfD_did1 SE_2024_CDU_did1 SE_2024_FDP_did1 SE_2024_opposition_did1 SE_2024_Wahlb_did1, bylabel(State election) || ///
RE_2024_Gruene_did1 RE_2024_Linke_did1 RE_2024_SPD_did1 RE_2024_coalition_did1 RE_2024_AfD_did1 RE_2024_CDU_did1 RE_2024_FDP_did1 RE_2024_opposition_did1 RE_2024_Wahlb_did1, bylabel(Regional election) || ///
NE_2021_Gruene_did3 NE_2021_Linke_did3 NE_2021_SPD_did3 NE_2021_coalition_did3 NE_2021_AfD_did3 NE_2021_CDU_did3 NE_2021_FDP_did3 NE_2021_opposition_did3 NE_2021_Wahlb_did3, bylabel("") ||  ///
SE_2024_Gruene_did3 SE_2024_Linke_did3 SE_2024_SPD_did3 SE_2024_coalition_did3 SE_2024_AfD_did3 SE_2024_CDU_did3 SE_2024_FDP_did3 SE_2024_opposition_did3 SE_2024_Wahlb_did3, bylabel("") ||  ///
RE_2024_Gruene_did3 RE_2024_Linke_did3 RE_2024_SPD_did3 RE_2024_coalition_did3 RE_2024_AfD_did3 RE_2024_CDU_did3 RE_2024_FDP_did3 RE_2024_opposition_did3 RE_2024_Wahlb_did3, bylabel("") ||  ///
NE_2021_Gruene_did5 NE_2021_Linke_did5 NE_2021_SPD_did5 NE_2021_coalition_did5 NE_2021_AfD_did5 NE_2021_CDU_did5 NE_2021_FDP_did5 NE_2021_opposition_did5 NE_2021_Wahlb_did5, bylabel("") ||  ///
SE_2024_Gruene_did5 SE_2024_Linke_did5 SE_2024_SPD_did5 SE_2024_coalition_did5 SE_2024_AfD_did5 SE_2024_CDU_did5 SE_2024_FDP_did5 SE_2024_opposition_did5 SE_2024_Wahlb_did5, bylabel("") ||  ///
RE_2024_Gruene_did5 RE_2024_Linke_did5 RE_2024_SPD_did5 RE_2024_coalition_did5 RE_2024_AfD_did5 RE_2024_CDU_did5 RE_2024_FDP_did5 RE_2024_opposition_did5 RE_2024_Wahlb_did5, bylabel("") ||  ///
NE_2021_Gruene_did10 NE_2021_Linke_did10 NE_2021_SPD_did10 NE_2021_coalition_did10 NE_2021_AfD_did10 NE_2021_CDU_did10 NE_2021_FDP_did10 NE_2021_opposition_did10 NE_2021_Wahlb_did10, bylabel("") || ///
SE_2024_Gruene_did10 SE_2024_Linke_did10 SE_2024_SPD_did10 SE_2024_coalition_did10 SE_2024_AfD_did10 SE_2024_CDU_did10 SE_2024_FDP_did10 SE_2024_opposition_did10 SE_2024_Wahlb_did10, bylabel("") || ///
RE_2024_Gruene_did10 RE_2024_Linke_did10 RE_2024_SPD_did10 RE_2024_coalition_did10 RE_2024_AfD_did10 RE_2024_CDU_did10 RE_2024_FDP_did10 RE_2024_opposition_did10 RE_2024_Wahlb_did10, bylabel("") ///
drop(_cons) xline(0) ciopts(recast(rcap)) keep(did) levels(95) ///
 legend(size(*0.75)cols(4)label(2 "Green")label(4 "Left")label(6 "SPD")label(8 "Coalition")label(10 "AfD")label(12 "CDU")label(14 "FDP")label(16 "Opposition")label(18 "Voter turnout")) ///
 byopts(cols(3))
graph play "Figure3_Results_PreTreatment.grec"
graph play "Figure4_Results_PostTreatment.grec"
graph save Graph "Figure4_Results_PostTreatment.gph", replace
graph export "Figure4_Results_Posttreatment.png", as(png) replace
 




 
** Heinemann elections
*Treatment <=1km
clear
use "Data_RegionalElection.dta", clear

gen time=.
replace time=0 if year==2019
replace time=1 if year==2024

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=1

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"

reg Share_Heinemann time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Heinemann_did1
outreg2 using "TableA5.xls", replace stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did time treated) alpha(0.001, 0.01, 0.05)


*Treatment <=3km
use "Data_RegionalElection.dta", clear

gen time=.
replace time=0 if year==2019
replace time=1 if year==2024

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=3

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"


reg Share_Heinemann time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Heinemann_did3
outreg2 using "TableA5.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did time treated) alpha(0.001, 0.01, 0.05)


collapseJ (mean) Share_Heinemann, by(year treated)
drop if year==2014
lab var year "Year"

twoway ///
  line Share_Heinemann year if treated==0, lp(dash) xlabel(2019 2024) ytitle("Share in %") subtitle("Rico Heinemann" "Voting results over time") || /// Linie für treated==0
  line Share_Heinemann year if treated==1, lp(solid) || /// Linie für treated==1
  scatteri 0 2019 0.7 2019, recast(line) lp(dot) lcolor(black) lwidth(thick) /// Vertikale Linie
  legend(cols(1) order(2 1 3) label(1 "Not treated") label(2 "Treated<=3 km") label(3 "Last election before treatment")) /// 
  name(panel10, replace)
graph save panel10 "Figure8B_Heinemann_Trends_Over_Time.gph", replace


  
*Treatment <=5km
use "Data_RegionalElection.dta", clear

gen time=.
replace time=0 if year==2019
replace time=1 if year==2024

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=5

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"

reg Share_Heinemann time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Heinemann_did5
outreg2 using "TableA5.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did time treated) alpha(0.001, 0.01, 0.05)


*Treatment <=10 km
use "Data_RegionalElection.dta", clear

gen time=.
replace time=0 if year==2019
replace time=1 if year==2024

gen treated=0
replace treated=1 if Distance_Apfelstaedt<=10

gen did=time*treated
lab var did "ATT"
lab var time "Time"
lab var treated "Treated"


reg Share_Heinemann time treated did i.ID_Community if year!=2014, vce(robust)
estimates store RE_2024_Heinemann_did10
outreg2 using "TableA5.xls", stat(coef se) dec(2) label addtext(Community fixed effects, Yes, Time fixed effects, Yes) adjr2 ctitle(Green) keep(did time treated) alpha(0.001, 0.01, 0.05)


coefplot RE_2024_Heinemann_did1 RE_2024_Heinemann_did3 RE_2024_Heinemann_did5 RE_2024_Heinemann_did10, bylabel(Heinemann) ///
 drop(_cons) xline(0) ciopts(recast(rcap)) keep(did) levels(95) subtitle("Rico Heinemann" "Results by treated defintions") ///
 legend(cols(1) size(*0.75)label(2 "Treated<= 1km")label(4 "Treated<= 3km")label(6 "Treated<= 5km")label(8 "Treated<= 10km"))  ///
   name(panel11, replace)
graph save panel11 "Figure8A_Results_Regional_Elections.gph", replace

graph combine "Figure8A_Results_Regional_Elections.gph" "Figure8B_Heinemann_Trends_Over_Time.gph" 
graph save Graph "Figure8_Results_Heinemann_Elections.gph", replace
graph export "Figure8_Results_Heinemann_Elections.png", as(png) replace

 


***Petition signing

use "Data_Petition.dta", clear

spmap petition_deciles using "coord_PLZ.dta", id(_ID) fcolor(Reds) osize(vthin) clmethod(custom) clbreaks(0.9 1.9 2.9 3.9 4.9 5.9 6.9 7.9 8.9 9.9) legorder(hilo) mosize(vvthin) legend(position(2) symx(*1.5) symy(*1.5) size(*1.5)) legjunction(-) legstyle(2) legtitle("Signees per 1k pop.") legend(label(2 "0 to 0.1") label(3 ">0.1 to 0.143") label(4 ">0.143 to 0.202") label(5 ">0.202 to 0.283") label(6 ">0.283 to 0.42") label(7 ">0.42 to 0.63")  label(8 ">0.63 to 1.2") label(9 ">1.2 to 8.2") label(10 "=68.1")) ///
polygon(data("coord_Riversystem.dta") ocolor(blue))
graph save Graph "Figure9_Petition_signing.gph", replace
graph export "Figure9_Petition_signing.png", as(png) replace


foreach i of numlist 3 5 10 20 30 40 50 60 70 80 90 100 {
gen treated`i'=0
replace treated`i'=1 if distance_Apfelstaedt<=`i'
lab var treated`i' "Treated<=`i' km"
}


regress petition_rate treated5 treated10 treated30 treated50 treated100 sw_watershed, vce(robust)
outreg2 using "Table3.xls", replace stat(coef se) dec(2) label adjr2 ctitle(Dummy treatment) alpha(0.001, 0.01, 0.05)

regress petition_rate distance_Apfelstaedt sq_distance_Apfelstaedt sw_watershed
outreg2 using "Table3.xls", stat(coef se) dec(2) label adjr2 ctitle(Squared distance) alpha(0.001, 0.01, 0.05)

fp <distance_Apfelstaedt>: regress petition_rate <distance_Apfelstaedt> sw_watershed
outreg2 using "Table3.xls", stat(coef se) dec(2) label adjr2 ctitle(Fractional polynomial regression) alpha(0.001, 0.01, 0.05)

